import { Elysia } from 'elysia';
import {
  getProducts,
  getProduct,
  createProduct,
  updateProduct,
  deleteProduct,
  getProductTypes
} from '../controllers/productController';
import { guestAccessMiddleware } from '../middleware/auth';

export const productRoutes = new Elysia({ prefix: '/products' })
  // 公开路由 - 前台展示
  .get('/', getProducts)
  .get('/types', getProductTypes)
  .get('/:id', getProduct)
  
  // 需要登录权限的路由（游客可查看，管理员可编辑）
  .use(guestAccessMiddleware())
  .get('/admin', getProducts) // 后台查看产品列表
  .get('/admin/:id', getProduct) // 后台查看产品详情
  .post('/', createProduct)
  .put('/:id', updateProduct)
  .delete('/:id', deleteProduct);